<?php

	require_once("fta.201003310000/fta.php");
	fta_registerModules(
		array(
		"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
		"site/components/MAIClasses",
		"FTAFormMailer/ftaFormMailer",
	));

	$classId = extractStringWithKeyFromArray("productId", $_REQUEST, null);

	//echo "class = $class";

	$o = mai_getSharedClassesObject();
	$class = $o->getClass($classId);

	if($class == false){
		header("location: /Classes/");
	}

	if(isset($_POST['member'])){
		$_POST['member'] = 'true';
	} else {
		$_POST['member'] = 'false';
	}

	//echo "class = <pre>";print_r($class); echo "</pre>";

	//Need to determine type of class so that we know which form to use.
	$classGroupId = $class->url;
	$classGroupsForChildren = array('2131', '2132', '2138', '2140', '2141', '2144', '2147');
	if(in_array($classGroupId, $classGroupsForChildren)){
		$formId = 2462;
	} else {
		$formId = 2461;
	}






	$authInfo = setupPublicUser();

	//ie cluster fuck
	$submit_x = extractBooleanWithKeyFromArray('enrol-button_x',$_POST,false);
	$submit_y = extractBooleanWithKeyFromArray('enrol-button_y',$_POST,false);
	$submit = ($submit_x || $submit_y);
	$submit = extractBooleanWithKeyFromArray('enrol-button',$_POST,$submit);
	//echo "submit = <pre>";print_r($submit);echo "</pre><br /><br />";

	$formDescriptor = fta_getFormMailerFormDescriptor($formId,$db);

	$formSent = false;
	if ( $submit ) {
		$invalidFields = array();

		// validate the form..
			$extractedFormData = fta_formMailerValidateFormData($formDescriptor, $_POST,$invalidFields);
			//echo "extracted Form Data = <pre>";print_r($extractedFormData);echo "</pre><br /><br />";
		//$recipients = array();
		//$formSent = fta_formMailerSendForm($formDescriptor,$_POST,$recipients, $authInfo, $invalidFields, $db );
		//echo "formSent = <pre>";print_r($formSent);echo "</pre><br /><br />";
		//echo "invalidFields = <pre>";print_r($invalidFields);echo "</pre><br /><br />";

		/*$toAddress = extractEmailWithKeyFromArray('email',$_REQUEST ,null);
		if ($formSent && !is_null($toAddress) && $formDescriptor->sendThankYouEmail){

			fta_formMailerSendThankYouEmail(
				array(
				$toAddress
				),$formDescriptor
			);
		}*/

		if (count($invalidFields) == 0 ){
		//	header("Location: /Cart/");
		//	echo "Form Sent";

		//Save data to session
			$_POST['formMailerId'] = "$formId";
			$formMailerDataForOrderItem = serialize($_POST);
			$_POST['formMailerDataForOrderItem'] = $formMailerDataForOrderItem;

			include_once("../html/cart.php");
			exit();die();
		}

	}








?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="Keywords" content="<?php echo $metadataKeywords; ?>" />
<meta name="Description" content="<?php echo $metadataDescription; ?>" />

<title><?php echo $pageTitle; ?> - Classes | Mairangi Arts Centre</title>
<?php include ("includes/external-files.php"); ?>
<script src="/js/jquery.inlined-forms.js" type="text/javascript"></script>


<?php include ("includes/analytics.php"); ?>
</head>

<body id="classes" class="classes-enrol">



<?php include ("includes/head.php"); ?>



<div id="container">


	<div id="content">


        <h1><a href="/Classes/"><?php echo $pageHeading; ?></a></h1>


        <div id="content-blocks">
           <div class="content-block block1 first-block">
           <?php if($class != false) { ?>

           <?php if($formId == 2461) { ?>
           <h2>Enrolment form for adult classes</h2>

			<p class="message">If you encounter problems making your payment you may need to contact your bank to ask for website capability to be enabled on your card</p>

		   <form class="class-enrol-form" method="post" action="<?= $_SERVER['REQUEST_URI'] ?>" enctype="multipart/form-data">

		        <?php /* ?>
		        <label>Name:</label>
		        <input class="input" name="name" type="text" />

		        <label>Email Address:</label>
		        <input class="input" name="email" type="text" />

		    	<?php */ ?>

		        <label>Enrol me in:</label><?php echo $class->title; ?>

		        <input type="hidden" name="class" value="<?php echo $class->title; ?>" />
		        <input type="hidden" name="productId" value="<?php echo $class->documentcode; ?>" />
		        <input type="hidden" name="returnUrl" value="/Classes/Enrolment-Form/" />
		        <input type="hidden" name="orderStep" value="orderItem" />
		        <input type="hidden" name="quantity" value="1" />







		        <div>

		        <input type="checkbox" <?php echo fta_getFormMailerInputIdAndValue('member',$_REQUEST, $formDescriptor); if($_POST['member'] == "true"){ echo "checked"; } ?> /> <label style="display: inline;" for="member">Are you a Member? (please tick if applicable to receive your membership discount)</label>
		        <?php echo fta_getFormMailerValidationMessageForField('member', $invalidFields, $formDescriptor); ?>
		        </div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('memberNo',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
		        <label for="memberNo" class="inlinedtrim($inputValues[2]) != 'value=""'">Membership No. (please enter if applicable to receive your discount)</label>
		        <input class="input-text" type="text" <?php echo $inputValue; ?> />
		        <?php echo fta_getFormMailerValidationMessageForField('memberNo', $invalidFields, $formDescriptor); ?>
		        </div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('firstName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="firstName" class="inlinedtrim($inputValues[2]) != 'value=""'">First Name:</label>
                    <input class="input-text" <?php echo $inputValue; ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('firstName', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('lastName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="lastName" class="inlinedtrim($inputValues[2]) != 'value=""'">Last Name:</label>
                    <input class="input-text" <?php echo $inputValue; ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('lastName', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="email" class="inlinedtrim($inputValues[2]) != 'value=""'">Email:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('email', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="phone" class="inlinedtrim($inputValues[2]) != 'value=""'">Phone:()</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('phone', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('mobile',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="mobile" class="inlinedtrim($inputValues[2]) != 'value=""'">Mobile:()</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('mobile',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('mobile', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('street',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="street" class="inlinedtrim($inputValues[2]) != 'value=""'">Address Line 1:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('street',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('street', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('suburb',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="suburb" class="inlinedtrim($inputValues[2]) != 'value=""'">Address Line 2:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('suburb',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('suburb', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('city',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="city" class="inlinedtrim($inputValues[2]) != 'value=""'">Town/City:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('city',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('city', $invalidFields, $formDescriptor); ?>
				</div>




		        <input class="enrol-button" name="enrol-button" type="submit" value='1' />
		    </form>

		    <?php } else { ?>




		    <h2>Enrolment form for children's / young adults classes</h2>
		   <form class="class-enrol-form" method="post" action="<?= $_SERVER['REQUEST_URI'] ?>" enctype="multipart/form-data">

		        <?php /* ?>
		        <label>Name:</label>
		        <input class="input" name="name" type="text" />

		        <label>Email Address:</label>
		        <input class="input" name="email" type="text" />

		    	<?php */ ?>

		        <label>Enrol me in:</label><?php echo $class->title; ?>

		        <input type="hidden" name="class" value="<?php echo $class->title; ?>" />
		        <input type="hidden" name="productId" value="<?php echo $class->documentcode; ?>" />
		        <input type="hidden" name="returnUrl" value="/Classes/Enrolment-Form/" />
		        <input type="hidden" name="orderStep" value="orderItem" />
		        <input type="hidden" name="quantity" value="1" />







		        <div>

		        <input type="checkbox" <?php echo fta_getFormMailerInputIdAndValue('member',$_REQUEST, $formDescriptor); if($_POST['member'] == "true"){ echo "checked"; } ?> value="Yes" /> <label style="display: inline;" for="member">Are you a Member?</label>
		        <?php echo fta_getFormMailerValidationMessageForField('member', $invalidFields, $formDescriptor); ?>
		        </div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('memberNo',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
		        <label for="memberNo" class="inlinedtrim($inputValues[2]) != 'value=""'">Membership No.</label>
		        <input class="input-text" type="text" <?php echo fta_getFormMailerInputIdAndValue('memberNo',$_REQUEST, $formDescriptor); ?> />
		        <?php echo fta_getFormMailerValidationMessageForField('memberNo', $invalidFields, $formDescriptor); ?>
		        </div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('childFirstName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="childFirstName" class="inlinedtrim($inputValues[2]) != 'value=""'">Child's First Name:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('childFirstName',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('childFirstName', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('childLastName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="childLastName" class="inlinedtrim($inputValues[2]) != 'value=""'">Child's Last Name:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('childLastName',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('childLastName', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('childDOB',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="childDOB" class="inlinedtrim($inputValues[2]) != 'value=""'">Child's Date of Birth:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('childDOB',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('childDOB', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('firstName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="firstName" class="inlinedtrim($inputValues[2]) != 'value=""'">Parent / Guardian First Name:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('firstName',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('firstName', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('lastName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="lastName" class="inlinedtrim($inputValues[2]) != 'value=""'">Parent / Guardian Last Name:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('lastName',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('lastName', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="email" class="inlinedtrim($inputValues[2]) != 'value=""'">Email:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('email', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="phone" class="inlinedtrim($inputValues[2]) != 'value=""'">Phone:()</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('phone', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('mobile',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="mobile" class="inlinedtrim($inputValues[2]) != 'value=""'">Mobile:()</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('mobile',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('mobile', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('street',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="street" class="inlinedtrim($inputValues[2]) != 'value=""'">Address Line 1:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('street',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('street', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('suburb',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="suburb" class="inlinedtrim($inputValues[2]) != 'value=""'">Address Line 2:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('suburb',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('suburb', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('city',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="city" class="inlinedtrim($inputValues[2]) != 'value=""'">Town/City:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('city',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('city', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('altFirstName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="altFirstName" class="inlinedtrim($inputValues[2]) != 'value=""'">Alternate Contact First Name:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('altFirstName',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('altFirstName', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('altLastName',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="altLastName" class="inlinedtrim($inputValues[2]) != 'value=""'">Alternate Contact Last Name:</label>
                    <input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('altLastName',$_REQUEST, $formDescriptor); ?> />
                    <?php echo fta_getFormMailerValidationMessageForField('altLastName', $invalidFields, $formDescriptor); ?>
				</div>

		        <div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('altPhone',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="altPhone" class="inlinedtrim($inputValues[2]) != 'value=""'">Alternate Contact Phone:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('altPhone',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('altPhone', $invalidFields, $formDescriptor); ?>
				</div>

				<div>
		        <?php
		        	$inputValue = '';
		        	$inputValues = '';
		        	ob_start();
		        	fta_getFormMailerInputIdAndValue('altMobile',$_REQUEST, $formDescriptor);
		        	$inputValue = ob_get_clean();
		        	$inputValues = explode(" ", $inputValue);
		        ?>
                    <label for="altMobile" class="inlinedtrim($inputValues[2]) != 'value=""'">Alternate Contact Mobile:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('altMobile',$_REQUEST, $formDescriptor); ?>/>
                    <?= fta_getFormMailerValidationMessageForField('altMobile', $invalidFields, $formDescriptor); ?>
				</div>

		        <input class="enrol-button" name="enrol-button" type="submit" value='1'>
		    </form>

		    	<?php } ?>


		    <?php } ?>





		    </div>



		</div><!-- Content-blocks ends -->


		<div id="supplementary-content">
			<?php echo $pageContent; ?>
		</div>





   </div><!-- Content ends -->


	<?php include ("includes/classesSubNav.php"); ?><!-- Sub-nav ends -->


</div><!-- Container ends -->


<?php include ("includes/foot.php"); ?>


</body>

</html>